
//
//  SystemMessageCell.m
//  bestkeep
//
//  Created by bj on 2016/11/17.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "SystemMessageCell.h"
#import "Masonry.h"
#import "SystemMessageModel.h"
#import "BKMyCommon.h"
#import "BK_OD_Color.h"
@implementation SystemMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.bgView = [[UIView alloc] init];
        _bgView.backgroundColor = RGBCOLOR(245, 245, 245, 1.0);
        [self.contentView addSubview:self.bgView];
        
        self.title = [[UILabel alloc] init];
//        self.title.backgroundColor=[UIColor yellowColor];
        self.title.textColor = kOrderBlack1;
        [self.contentView addSubview:self.title];
        self.title.font = [UIFont systemFontOfSize:15];
        
        self.timeLabel = [[UILabel alloc] init];
//        self.timeLabel.backgroundColor=[UIColor cyanColor];
        self.timeLabel.textColor = HexColor(0xB2B2B2);
        [self.contentView addSubview:self.timeLabel];
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        
        self.detaiLabel = [[UILabel alloc] init];
        self.detaiLabel.numberOfLines = 0;
//        self.detaiLabel.backgroundColor=[UIColor redColor];
        self.detaiLabel.textColor = BK_MY_COLOR_02;
       // [self.detaiLabel sizeToFit];
        self.detaiLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.detaiLabel];
        
        self.detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.bgView addSubview:self.detailButton];
        [self.detailButton setTitle:@"查看详情>" forState:UIControlStateNormal];
        self.detailButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.detailButton setTitleColor:BK_MY_COLOR_02 forState:UIControlStateNormal];

        self.lineView = [[UIView alloc] init];
        self.lineView.backgroundColor = kOrderLineGrey2;
        self.lineView.alpha = 0.6;
        [self.contentView addSubview:self.lineView];
        
        self.headImg = [[UIImageView alloc] init];
        self.headImg.image = [UIImage imageNamed:@"systemMessage"];
        [self.contentView addSubview:self.headImg];
        
        [self.headImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(ApplicationBackGauge);
            make.top.mas_equalTo(self.contentView.mas_top).offset(10);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.headImg.mas_right).offset(10);
            make.top.mas_equalTo(self.contentView.mas_top).offset(10);
            make.height.mas_equalTo(16);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.headImg.mas_right).offset(10);
            make.top.mas_equalTo(self.title.mas_bottom).offset(2);
            make.height.mas_equalTo(16);
        }];
        
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right);
            make.left.mas_equalTo(self.contentView.mas_left);
            make.bottom.mas_equalTo(self.contentView.mas_bottom);
            make.height.mas_equalTo(0.6);
        }];
        
        [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.bgView.mas_left).offset(10);
            make.height.mas_equalTo(21);
            make.bottom.mas_equalTo(self.bgView.mas_bottom).offset(-10);
        }];
    }
    return self;
}

- (void)setModel:(SystemMessageModel *)model {
    _model = model;
    _title.text = model.title;
    _timeLabel.text = model.time;
    _detaiLabel.text = model.detail;
    [self initlizeSubViews];
}

- (void)initlizeSubViews {
    __weak typeof (self)weakSelf = self;
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).offset(ApplicationBackGauge+40);
        make.top.mas_equalTo(weakSelf.contentView.mas_top).offset(50);
        make.width.mas_equalTo(ScreenWidth - 40-ApplicationBackGauge*2);
        make.height.mas_equalTo(47 + _model.a);
    }] ;

    [self.detaiLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.bgView.mas_left).offset(10);
        make.top.mas_equalTo(weakSelf.bgView.mas_top).offset(10);
        make.width.mas_equalTo(ScreenWidth - 40-ApplicationBackGauge*2-15);
        make.height.mas_equalTo(_model.a + 1);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
